﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LGCourt.Logic.BLL;
using LGCourt.Logic.NBL.DBEntities;
using LGCourt.Logic.Common;
using lgweb.common;
using KMFrame.Permission.Util;
using KMFrame.Core;

namespace lgweb.inside.department
{
    public partial class index : NeedValidatePage
    {
        public string _DetpName = string.Empty;
        public string _DeptID = "0";
        public string _deptCode = string.Empty;
        public string _picUrl = string.Empty;
        string _cateName = string.Empty;
        protected new void Page_Load(object sender, EventArgs e)
        {
            base.Page_Load(sender, e);
            if (!this.IsPostBack)
            {
                this.hdOADomain.Value = System.Configuration.ConfigurationManager.AppSettings["OADomain"];
                _picUrl = System.Configuration.ConfigurationManager.AppSettings["InfoManage"];
                _picUrl = string.IsNullOrEmpty(_picUrl) ? "http://www.lgfygp.gov.cn/lgmanage/Systems/upload/" : _picUrl;
                //  GetUserInfo();
                GetParam();
                GetNewsList();
            }
        }

        //获取个人信息
        private void GetUserInfo()
        {
            OA bll = new OA();
            vOAUser result = (vOAUser)bll.GetUserInfo(SessionBox.GetUserSession().UserID);

            if (result != null)
            {
                // this.topUsername.InnerHtml = result.realname;
            }
        }

        private void GetParam()
        {
            this._DeptID = string.IsNullOrEmpty(Request.QueryString["deptid"]) ? "0" : Request.QueryString["deptid"].ToString();
            this._deptCode = string.IsNullOrEmpty(Request.QueryString["Code"]) ? "ZZC" : Request.QueryString["Code"].ToString();
        }

        //获取资讯类信息列表
        private void GetNewsList()
        {
            ColInfo colInfoBLL = new ColInfo();
            DeptClassCondition param = new DeptClassCondition();

            if (_DeptID == "0")
            {
                DepartmentHandler departmentHandler = new DepartmentHandler();
                Department department = departmentHandler.GetDepartmentInfo(_deptCode);
                if (department != null)
                {

                    _DetpName = department.Name;
                }
                //根据名称取部门ID
                param.Source = _DetpName;
            }
            else
            {
                param.ClassID = int.Parse(_DeptID);
            }
            param.Name = "部门";
            V_DICT_SOURCE deptInfo = colInfoBLL.GetDeptSourceInfo(param);
            if (deptInfo == null)
            {
                deptInfo = new V_DICT_SOURCE();
                deptInfo.ID = 1;
            }
            _DeptID = deptInfo.ID.ToString();
            _DetpName = deptInfo.Source;
            this.topDepart1.InnerHtml = _DetpName;//部门名称
            param = new DeptClassCondition();
            param.Name = "部门栏目";
            List<V_DICT_SOURCE> classInfoList = colInfoBLL.GetDeptSourceList(param);


            //部门信息
            DeptCondition deptParam = new DeptCondition();
            deptParam.DeptID = deptInfo.ID.GetValueOrDefault(0);
            LGFY_Platform_Index deptIndex = colInfoBLL.GetDeptIndexInfo(deptParam);
            if (deptIndex != null)
            {
                this.divDeptLD.InnerHtml = deptIndex.Leader;
                this.divDeptZN.InnerHtml = deptIndex.FunctionsIndex;
                this.divDeptFG.InnerHtml = deptIndex.StaffIndex;
                spInfoEditer.InnerText = deptIndex.Managers;
            }
            this.aDeptZNMore.HRef = string.Format("/inside/department/deptinfo.aspx?cate=6&deptid={0}&type=1", _DeptID);
            this.aDeptFGMore.HRef = string.Format("/inside/department/deptinfo.aspx?cate=6&deptid={0}&type=2", _DeptID);

            //部门栏目
            List<IF_DeptClass> deptClassList = colInfoBLL.GetDeptClassList(deptParam);
            IF_DeptClass deptClass = null;
            //部门动态      
            //BBS bbsBLL = new BBS();
            //InfoCondition infoParam = new InfoCondition();
            //infoParam.PageSize = 9;
            //infoParam.InfoTag = "部门动态";
            //infoParam.UpInfoTag = deptName;
            //IEnumerable<vPortalArticleTitleEx> DTList = bbsBLL.GetNewsInfoTop(infoParam);
            //部门动态 改为信息报送   
            OA bll = new OA();
            OANoticeCondition noticeParam = new OANoticeCondition();
            noticeParam.UserID = this.SessionInfo.UserID;
            noticeParam.DeptName = _DetpName;
            noticeParam.PageIndex = 1;
            noticeParam.PageSize = 8;
            PageResult result = (PageResult)bll.GetXinXiBaoSongPage(noticeParam);
            if (result != null && result.ResultList != null)
            {
                this.rptdeptDT.DataSource = (List<vOAXinXiBaoSong>)result.ResultList;
                this.rptdeptDT.DataBind();
            }
            this.aBMDTMore.HRef = string.Format("/inside/department/notice.aspx?cate=1&deptid={0}", _DeptID);

            //重要文件
            //infoParam.PageSize = 9;
            //infoParam.InfoTag = "重要文件";
            //IEnumerable<vPortalArticleTitleEx> FILEList = bbsBLL.GetNewsInfoTop(infoParam);
            deptParam.PageSize = 8;
            deptParam.ClassID = classInfoList.Count >= 1 ? classInfoList[0].ID.GetValueOrDefault(0) : DeptInfoClassID.ZYWJ;
            deptClass = deptClassList.Where(a => a.ClassID == deptParam.ClassID).FirstOrDefault();
            this.hClassName2.InnerText = deptClass != null ? deptClass.ClassName : "重要文件";
            List<LGFY_Platform_Bmxx> FILEList = colInfoBLL.GetDeptColInfoTop(deptParam);
            if (FILEList != null)
            {
                this.rptdeptFILE.DataSource = FILEList;
                this.rptdeptFILE.DataBind();
            }
            this.aZYWJmore.HRef = string.Format("/inside/department/list.aspx?cate=2&classid={0}&deptid={1}", classInfoList.Count >= 1 ? classInfoList[0].ID.GetValueOrDefault(0) : 0, _DeptID);

            //政治学习
            //infoParam.PageSize = 9;
            //infoParam.InfoTag = "政治学习";
            //IEnumerable<vPortalArticleTitleEx> XXList = bbsBLL.GetNewsInfoTop(infoParam);
            deptParam.ClassID = classInfoList.Count >= 2 ? classInfoList[1].ID.GetValueOrDefault(0) : DeptInfoClassID.ZZXX;
            deptClass = deptClassList.Where(a => a.ClassID == deptParam.ClassID).FirstOrDefault();
            this.hClassName3.InnerText = deptClass != null ? deptClass.ClassName : "政治学习";
            List<LGFY_Platform_Bmxx> XXList = colInfoBLL.GetDeptColInfoTop(deptParam);
            if (XXList != null)
            {
                this.rptdeptXX.DataSource = XXList;
                this.rptdeptXX.DataBind();
            }
            this.aZZXXmore.HRef = string.Format("/inside/department/list.aspx?cate=3&classid={0}&deptid={1}", classInfoList.Count >= 2 ? classInfoList[1].ID.GetValueOrDefault(0) : 0, _DeptID);

            //部门风采
            //infoParam.PageSize = 9;
            //infoParam.InfoTag = "部门风采";
            //IEnumerable<vPortalArticleTitleEx> FCList = bbsBLL.GetNewsInfoTop(infoParam);
            deptParam.ClassID = classInfoList.Count >= 3 ? classInfoList[2].ID.GetValueOrDefault(0) : DeptInfoClassID.BMFC;
            deptClass = deptClassList.Where(a => a.ClassID == deptParam.ClassID).FirstOrDefault();
            this.hClassName4.InnerText = deptClass != null ? deptClass.ClassName : "部门风采";
            List<LGFY_Platform_Bmxx> FCList = colInfoBLL.GetDeptColInfoTop(deptParam);
            if (FCList != null)
            {
                this.rptdeptFC.DataSource = FCList;
                this.rptdeptFC.DataBind();
            }
            this.aBMFCMore.HRef = string.Format("/inside/department/list.aspx?cate=4&classid={0}&deptid={1}", classInfoList.Count >= 3 ? classInfoList[2].ID.GetValueOrDefault(0) : 0, _DeptID);

            //办公助手
            //infoParam.PageSize = 9;
            //infoParam.InfoTag = "办公助手";
            //IEnumerable<vPortalArticleTitleEx> CSList = bbsBLL.GetNewsInfoTop(infoParam);
            deptParam.ClassID = classInfoList.Count >= 4 ? classInfoList[3].ID.GetValueOrDefault(0) : DeptInfoClassID.BGZS;
            deptClass = deptClassList.Where(a => a.ClassID == deptParam.ClassID).FirstOrDefault();
            this.hClassName5.InnerText = deptClass != null ? deptClass.ClassName : "办公助手";
            List<LGFY_Platform_Bmxx> CSList = colInfoBLL.GetDeptColInfoTop(deptParam);
            if (CSList != null)
            {
                this.rptdeptCS.DataSource = CSList;
                this.rptdeptCS.DataBind();
            }
            this.aBGZSmore.HRef = string.Format("/inside/department/list.aspx?cate=5&classid={0}&deptid={1}", classInfoList.Count >= 4 ? classInfoList[3].ID.GetValueOrDefault(0) : 0, _DeptID);

            //顶部图片
            //infoParam.PageSize = 1;
            //infoParam.InfoTag = "顶部图片";
            //IEnumerable<vPortalArticleTitleEx> ImgList = bbsBLL.GetNewsInfoTop(infoParam);
            //deptParam.PageSize = 1;
            //deptParam.IsPicRoll = false;
            ////deptParam.ClassID = DeptInfoClassID.BGZS;
            //List<LGFY_Platform_Bmxx> ImgList = colInfoBLL.GetDeptColInfoTop(deptParam);
            //if (ImgList != null)
            //{
            //    this.rptImgList.DataSource = ImgList;
            //    this.rptImgList.DataBind();
            //}

            //轮播图片
            //infoParam.PageSize = 5;
            //infoParam.InfoTag = "轮播图片";
            //IEnumerable<vPortalArticleTitleEx> LBList = bbsBLL.GetNewsInfoTop(infoParam);
            deptParam = new DeptCondition();
            deptParam.DeptID = deptInfo.ID.GetValueOrDefault(0);
            deptParam.PageSize = 6;
            deptParam.IsPicRoll = true;
            List<LGFY_Platform_Bmxx> LBList = colInfoBLL.GetDeptColInfoTop(deptParam);
            if (LBList != null)
            {
                this.rptlbList1.DataSource = LBList;
                this.rptlbList1.DataBind();

                this.rptlbList2.DataSource = LBList;
                this.rptlbList2.DataBind();
            }
        }

    }
}
